<template>
  <div>
     <Row>
        <label>开始时间:</label>
        <Date-picker v-model="startDay" placeholder="开始日期" format="yyyy-MM-dd"></Date-picker>
        <label>结束时间:</label>
        <Date-picker v-model="endDay" placeholder="结束日期" format="yyyy-MM-dd"></Date-picker>
        <Button type="primary" @click="onSearch">查询</Button>
    </Row>
    <br/>
    <Table :border="true" :stripe="true" :show-header="true" :height="500" :data="tableData" :columns="tableColumns"></Table>
  </div>
 
</template>
<script>

import {getRoleDayRecordAnalys} from '@/api/game.js'
import {getVO} from '@/common/proto-vo.js'
export default {
  data () {
    return {
      tableData: [],
      startDay: '',
      endDay: ''
    }
  },
  created () {
    this.endDay = new Date()
    this.startDay = new Date().setDate(new Date().getDate() - 7)
    this.onSearch()
  },
  methods: {
    onSearch () {
      let sSendDay = 0
      let eSendDay = 0
      if (this.startDay !== '') {
        let sDay = new Date(this.startDay)
        sSendDay = '' + sDay.getFullYear() + ((sDay.getMonth() + 1) < 10 ? '0' + (sDay.getMonth() + 1) : (sDay.getMonth() + 1)) + (sDay.getDate() < 10 ? '0' + sDay.getDate() : sDay.getDate())
        sSendDay = parseInt(sSendDay)
      }
      if (this.endDay !== '') {
        let eDay = new Date(this.endDay)
        eSendDay = '' + eDay.getFullYear() + ((eDay.getMonth() + 1) < 10 ? '0' + (eDay.getMonth() + 1) : (eDay.getMonth() + 1)) + (eDay.getDate() < 10 ? '0' + eDay.getDate() : eDay.getDate())
        eSendDay = parseInt(eSendDay)
      }

      console.log('sSendDay:', sSendDay, ',eSendDay:', eSendDay)
      getRoleDayRecordAnalys(sSendDay, eSendDay).then((data) => {
        if (!data) {
          return
        }
        this.tableData = []
        let DayRecordAnalysVO = getVO('DayRecordAnalysVO')
        let pv = data.data.data
        let len = pv.data.length
        for (let i = 0; i < len; i++) {
          let vo = DayRecordAnalysVO.decode(pv.data[i])
          vo.count = vo.count.toNumber()
          this.tableData.push(vo)
        }
        console.log(this.tableData)
      })
    }
  },
  computed: {
    tableColumns () {
      let cols = [
        {
          title: '时间',
          key: 'day',
          align: 'center'
        },
        {
          title: '游戏局数',
          key: 'count',
          align: 'center'
        }
      ]
      return cols
    }
  }
}

</script>

<style scoped>
.bottom-page{
  margin-top: 5px;
  margin-bottom: 10px;
  float: right;
}
</style>
